package br.uff.javaavancado.util;

//import exceptions.BDException;
import br.uff.javaavancado.exception.BDException;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Conexao {
    
    private static Conexao conexao = null;
    private static Connection conex = null;
    private static String usuario = "suporte";
    private static String senha = "tzzk7662";
    
    
    private Conexao() {
        try {
//            Class.forName("oracle.jdbc.driver.OracleDriver");
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println('\n' + "Classe do driver de banco de dados n�o encontrada.");
            e.printStackTrace();
            System.exit(1);
        }
    }
    
    public static Connection getConnection() {
        if (conexao == null) {
            conexao = new Conexao();
        }
        try{
//            conex = DriverManager.getConnection("jdbc:oracle:thin:@sbd:1521:orcl",usuario,senha);
            conex = DriverManager.getConnection("jdbc:postgresql://id.uff.br:5432/kanntemp", usuario, senha);
        } catch (SQLException e) {
            System.out.println('\n' + "Erro na conex�o com o banco.");
            e.printStackTrace();
            System.exit(1);
        }
        return conexao.conex;
    }
    
    public static void close() {
        try {
            conex.close();
        } catch(SQLException e) {
        }
    }
    
    
}


